{"Name":"z_API send SMTP from work order report","Active":true,"Notes":"Example shows how to send email via an API call when that work order is rendered.","Roles":124927,"AType":34,"IncludeWoItemDescendants":false,"Template":"\n\n\n\n\t
\n\t\t{{#each ayReportData}}\t\n\t\t\n\t\t\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{#if CustomerContactName}}\n\t\t\t\t\t{{else}}{{/if}}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\n\n\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\n\n\t\t\t\t{{#each Items}}\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\n\t\t\t\t\n\n\t\t\t\t{{#each Units}}\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t{{/each}}\n\t\t\t\t\n\n\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t{{#each ScheduledUsers}}\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t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t\t\n\t\t\t\t{{/each}}\n\t\t\t\t\n\t\t\t\t{{#if Parts}}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t{{/if}}\n\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t{{/each}}\n\t\t\t\t\n\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{#if TechSignature}} \n\t\t\t\t\t{{else}}{{/if}}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{#if CustomerSignature}} \n\t\t\t\t\t{{else}}{{/if}}\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\n\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{#if TechSignatureCaptured}} \n\t\t\t\t\t{{else}}{{/if}}\n\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t{{#if CustomerSignatureCaptured}} \n\t\t\t\t\t{{else}}{{/if}}\n\t\t\t\t\n\t\t\t\n\t\t
{{ayT 'Customer'}}{{CustomerViz}}{{../ayServerMetaData.CompanyName}}
{{ayT 'AddressTypePhysical'}}{{Address}}, {{City}}{{ayT 'WorkOrderSerialNumber'}}{{Serial}}
{{ayT 'WorkOrderCustomerContactName'}}{{CustomerContactName}} {{CustomerPhone1Viz}}\n\t\t\t\t\t\t{{CustomerEmailAddressViz}}{{CustomerPhone1Viz}} {{CustomerEmailAddressViz}}{{ayT 'WorkOrderServiceDate'}}{{ayDate ServiceDate}}
 
 
{{ayT 'WorkOrderSummary'}}{{Notes}}
{{ayT 'WorkOrderCloseByDate'}}{{ayDateTime CompleteByDate}}
{{ayT 'CustomerTechNotes'}}{{CustomerTechNotesViz}}
{{ayT\n\t\t\t\t\t\t'WorkOrderItemPriorityID'}}\n\t\t\t\t\t\t{{WorkOrderItemPriorityNameViz}}{{ayT 'WorkOrderItemRequestDate'}}{{ayDateTime RequestDate}}{{ayT\n\t\t\t\t\t\t'WorkOrderItemWorkOrderStatusID'}}\n\t\t\t\t\t\t{{WorkOrderItemStatusNameViz}}
{{ayT 'WorkOrderItemSummary'}} #{{Sequence}}{{Notes}}
{{ayT 'WorkOrderItemTechNotes'}}{{TechNotes}}
{{ayT 'Unit'}}{{UnitViz}} {{UnitModelNameViz}}
 
{{ayT 'NotifyEventScheduledOnWorkorder'}}{{UserViz}}As expected?Actual
 {{ayT 'WorkOrderItemScheduledUserStartDate'}}{{ayDateTime StartDate}}
 {{ayT 'WorkOrderItemScheduledUserStopDate'}}{{ayDateTime StopDate}}
 {{ayT 'WorkOrderItemScheduledUserServiceRateID'}}{{ServiceRateViz}}
 {{ayT 'WorkOrderItemScheduledUserEstimatedQuantity'}}{{EstimatedQuantity}}
 
{{ayT 'WorkOrderItemTaskWorkOrderItemTaskCompletionType'}}{{ayT 'WorkOrderItemTasks'}}
{{StatusViz}}\n\t\t\t\t\t\t\n\t\t\t\t\t\n\t\t\t\t\t\t\n\t\t\t\t\t{{Task}}
 
{{ayT 'WorkOrderItemPartQuantity'}}{{ayT 'WorkOrderItemPartPartWarehouseID'}}{{ayT 'Part'}}{{ayT 'WorkOrderItemPartUsed'}}
{{Quantity}}{{PartWarehouseViz}}{{PartNameViz}} {{PartDescriptionViz}}   {{ayT\n\t\t\t\t\t\t'PurchaseOrderItemSerialNumbers'}}: {{Serials}} {{PartNameViz}} {{PartDescriptionViz}}\n\t\t\t\t\t\t\n\t\t\t\t\t
 
{{ayT 'WorkOrderItemLaborServiceDetails'}}
 
 
 
 
 
{{ayT 'TechSignature'}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
 {{ayT 'CustomerSignature'}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
 
Date {{ayDateTime TechSignatureCaptured}} \n\t\t\t\t\t\t
\n\t\t\t\t\t
 Date {{ayDateTime CustomerSignatureCaptured}}\n\t\t\t\t\t\t
\n\t\t\t\t\t
\n\t\t{{/each}}\n\t
\n\n\n","Style":".singlePage\n{\npage-break-after: always;\n}\n\nbody {\n font-family: 'Helvetica', 'Helvetica Neue', Arial, sans-serif; \n}\n\n.reporttitle { \n margin-bottom: 20pt; \n font-weight: bold; \n font-size: 13pt; \n} \n\n\ntable { \n table-layout: fixed; \n font-family: 'Helvetica Neue', 'Helvetica', Helvetica, Arial, sans-serif;\n border-collapse: collapse;\n white-space: pre-wrap;\n font-size: 8pt;\n width: 100%;\n }\n\n\nth {\n height: 30px;\n text-align: left;\n color: #9e9e9e;\n}\n\n\ntbody tr {\n height: 10px;\n word-wrap: break-word;\n}\n\ntbody tr:nth-child(even) {\n background-color: #f8f8f8; /* MUST checkmark Print background in PDF Options for this to show */\n}\n\n\n.fontgreen {\n color: green;\n}\n.fontblue {\n color: blue;\n}\n.fontred {\n color:red;\n}\n\n\n.rightlean {\n text-align: right;\n}\n.leftlean {\n text-align: left;\n}\n.centerlean {\n text-align: center;\n}","JsPrerender":"async function ayPrepareData(reportData) {\n //this function (if present) is called with the report data \n //before the report is rendered\n //modify data as required here and return it to change the data before the report renders\n //see the help documentation for details\n\n await ayGetTranslations([\"WorkOrderCloseByDate\", \"WorkOrderServiceDate\", \"WorkOrderSerialNumber\", \"Customer\", \"WorkOrderSummary\", \"Unit\", \"WorkOrderItemSummary\", \"WorkOrderItemPartQuantity\", \"AddressTypePhysical\", \"WorkOrderCustomerContactName\", \"CustomerTechNotes\", \"WorkOrderItemTechNotes\", \"Part\", \"WorkOrderItemPartUsed\", \"WorkOrderItemPartPartWarehouseID\", \"PurchaseOrderItemSerialNumbers\", \"WorkOrderItemLaborServiceDetails\", \"WorkOrderItemScheduledUser\", \"NotifyEventScheduledOnWorkorder\", \"WorkOrderItemScheduledUserEstimatedQuantity\", \"WorkOrderItemScheduledUserStartDate\", \"WorkOrderItemScheduledUserStopDate\", \"WorkOrderItemScheduledUserServiceRateID\", \"WorkOrderItemTasks\", \"WorkOrderItemTaskWorkOrderItemTaskCompletionType\", \"CustomerSignature\", \"TechSignature\", \"WorkOrderItemPriorityID\", \"WorkOrderItemWorkOrderStatusID\", \"WorkOrderItemRequestDate\"]);\n\n //below checks if any parts have Serials to remove carriage returns so parts serials display on same line\n for (const EachWO of reportData.ayReportData) {\n for (const Item of EachWO.Items) {\n for (const Part of Item.Parts) {\n if (Part.Serials != null) {\n let s = Part.Serials;\n Part.Serials = s.replace(/[\\n\\r]+/g, ' ');\n }\n }\n }\n\n ////////////////////////////////////////////\n // Send an email on prepare \n // This example requires AyaNova 8.0.24 or newer\n // Note: this block of code is the only modification to the \n // stock work order report\n //\n\n //WARNING: Be *very* careful using this method, sending too high a volume of email\n //or engaging in what may be seen as spammy behavior could lead to having your \n //account, mail server or domain black listed. Make sure the recipients are expecting\n //to receive mail from you and provide an opt out procedure\n\n //Here, we'll use the CustomerEmailAddressViz property of the work order\n //as the email address directly.\n //See the API console https://ayanova.com/docs/api-console/ \n //for route notify/direct-smtp alternative options for addressing\n \n if (!!EachWO.CustomerEmailAddressViz.trim()) {\n \n let emailObject = {\n \"objectId\": 0,\n \"aType\": 0,\n \"toAddress\": EachWO.CustomerEmailAddressViz,\n \"subject\": `AttN:${EachWO.CustomerViz}`,\n \"textBody\": `WO: ${EachWO.Serial} test message plain text body`,\n \"htmlBody\": `

WO: ${EachWO.Serial}

test html format message text

`\n }\n await ayPostToAPI(\"notify/direct-smtp\", emailObject);\n }\n //////////////////////////////////////////////\n\n \n }\n\n\n return reportData;\n}","JsHelpers":"//custom helper so can do a direct comparison - i.e. if value equals xxxx, then show, else show yyyyy\n\nHandlebars.registerHelper('if_eq', function(a, b, opts) {\n if(a == b) // Or === depending on your needs\n return opts.fn(this);\n else\n return opts.inverse(this);\n});\n\n","RenderType":0,"HeaderTemplate":"  ","FooterTemplate":"                Printed date: PDFDate\nPage of                ","DisplayHeaderFooter":true,"PaperFormat":10,"Landscape":false,"MarginOptionsBottom":"15mm","MarginOptionsLeft":"20mm","MarginOptionsRight":"15mm","MarginOptionsTop":"10mm","PageRanges":null,"PreferCSSPageSize":false,"PrintBackground":true,"Scale":1.00000}